package com.msh.starter.common.web.controller;

import com.msh.frame.client.interfaces.IClassLoadLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Tag(name = "心跳测试-controller相关接口")
@RestController
@RequestMapping("/")
@ConditionalOnProperty(name = "msh.starter.web.controller.heartbeat.enable", havingValue = "true", matchIfMissing = true)
public class HeartbeatController implements IClassLoadLog {
  @Value("${msh.starter.web.controller.heartbeat.path:/healthz}")
  private String path;

  @Override
  public String logInfo() {
    return new StringBuilder()
        .append("----执行类 ")
        .append(HeartbeatController.class)
        .append("\r\n")
        .append("--------加载类 ")
        .append(HeartbeatController.class)
        .append("\r\n")
        .append("------------参数 ")
        .append("msh.starter.web.controller.heartbeat.path: ")
        .append(path)
        .append("\r\n")
        .toString();
  }

  @Operation(summary = "心跳测试")
  @GetMapping("${msh.starter.web.controller.heartbeat.path:/healthz}")
  public boolean test() {
    return true;
  }
}
